;
(function () {
	new Vue({
		el: '#incomeSureConfig',
		data: {
			isDefultArr: [{
				name: '是',
				code: 'Y'
			}, {
				name: '否',
				code: 'N'
			}],
			freeDateArr: [],
			isAmortize: 'Y',
			isRent: 'Y',
			isAmortizationArr: [],
			isnewArr: [],
			receivedAmortizationTypes: [],
			isAmortizationType: 'NM',
			data: [],
			projectId: hlUrlUtil.GetQueryString('id'),
			quanxian2: JSON.parse(localStorage.getItem('userMes')),
		},
		methods: {
			emptyChildData(i) {
				
			},
			setChildData(i) {
				
			},
			//免租期摊销方式
			freeDateAmortize() {
				hlhttp.get({
					url: 'configure/dict',
					data: {
						'module_code': 'CIWU',
						'config_name': 'CW_FREE_DATE_AMORTIZE'
					},
					success: data => {
						data.map(item => {
							item.name = item.dictName
							item.code = item.dictCode
						})
						this.freeDateArr = data
					}
				})
			},
			//收入确认分摊方式
			receivableAllocation() {
				hlhttp.get({
					url: 'configure/dict',
					data: {
						'module_code': 'CIWU',
						'config_name': 'CW_AMORTIZE_TYPE'
					},
					success: data => {
						data.map(item => {
							item.name = item.dictName
							item.code = item.dictCode
						})
						this.isAmortizationArr = data
					}
				})
			},
			//账单分摊分摊方式
			receivableAllocation2() {
				hlhttp.get({
					url: 'configure/dict',
					data: {
						'module_code': 'CIWU',
						'config_name': 'CW_BILL_AMORTIZE_TYPE'
					},
					success: data => {
						data.map(item => {
							item.name = item.dictName
							item.code = item.dictCode
						})
						this.isnewArr = data
					}
				})
			},
			//实收分摊方式
			actualIncome() {
				hlhttp.get({
					url: 'configure/dict',
					data: {
						'module_code': 'CIWU',
						'config_name': 'CW_RECEIVED_AMORTIZE_TYPE'
					},
					success: data => {
						data.map(item => {
							item.name = item.dictName
							item.code = item.dictCode
						})
						this.receivedAmortizationTypes = data
					}
				})
			},
			//获取收入请确认配置列表
			revenueRecognitionConfigsDt() {
				hlhttp.get({
					url: 'project/revenue_recognition_configs',
					data: {
						project_id: this.projectId
					},
					success: (data) => {
						data.map(item => {
							item.amortizeFlagArr = item.amortizeFlag ? [item.amortizeFlag] : []
							item.receivedAmortizeFlagArr = item.receivedAmortizeFlag ? [item.receivedAmortizeFlag] : []
							item.amortizationTypeArr = item.amortizationType ? [item.amortizationType] : []
							item.receivedAmortizationTypeArr = item.receivedAmortizationType ? [item.receivedAmortizationType] : []
							item.freeDateAmortizeArr = item.freeDateAmortize ? [item.freeDateAmortize] : []

							item.amountAmortizeFlag = item.amountAmortizeFlag ? [item.amountAmortizeFlag] : ['N'] //默认为否
							item.amountAmortizationType = item.amountAmortizationType ? [item.amountAmortizationType] : (item.amortizationType ? [item.amortizationType] : [])
						})
						console.log(data)
						this.data = data;
					}
				})
			},
			//保存
			submitSave() {
				let newArr = [];
				this.data.map(item => {
					newArr.push({
						"id": item.id,
						"amortize_flag": item.amortizeFlagArr.length ? item.amortizeFlagArr[0] : '#',
						"amortization_type": item.amortizationTypeArr.length ? item.amortizationTypeArr[0] : '#',
						"free_date_amortize": item.freeDateAmortizeArr.length ? item.freeDateAmortizeArr[0] : '#',
						"received_amortization_type": item.receivedAmortizationTypeArr.length ? item.receivedAmortizationTypeArr[0] : '#',
						"received_amortize_flag": item.receivedAmortizeFlagArr.length ? item.receivedAmortizeFlagArr[0] : '#',

						"amount_amortize_flag": item.amountAmortizeFlag.length ? item.amountAmortizeFlag[0] : '#',
						"amount_amortization_type": item.amountAmortizationType.length ? item.amountAmortizationType[0] : '#',
					})
				})
				hlhttp.put({
					url: 'project/revenue_recognition_configs',
					data: {
						configs: JSON.stringify(newArr)
					},
					success: () => {
						hl.toast('操作成功')
						this.revenueRecognitionConfigsDt()
					}
				})
			}
		},
		mounted() {
			this.revenueRecognitionConfigsDt()
			this.receivableAllocation()
			this.actualIncome()
			this.freeDateAmortize()
			this.receivableAllocation2()
		}
	})
}())